package com.wubo.sec.service;

import java.util.List;

import javax.annotation.security.RolesAllowed;

import com.wubo.sec.core.UserData;
import com.wubo.sec.model.User;

public interface IUserService {

	/**
	 * 根据登录名得到用户
	 * @param loginName
	 * @return
	 */
	User getByUsername(String username);
	/**
	 * 根据登录名得到用户
	 * @param username
	 * @param initAuth 是否需要加载用户和组对应的权限
	 * @return
	 */
	User getByUsername(String username, boolean initAuth);
	/**
	 * 用户登录成功时回调
	 * @param user
	 * @param ip
	 */
	void onUserLoginSuccess(UserData user, String ip);
	
	/**
	 * 当密码修改时回调
	 * @param user
	 * @param newpwd
	 */
	void onPasswordChange(UserData user, String newpwd);
	
	boolean isExist(String username);
	
	@RolesAllowed({"ADMIN", "USER_READ"})
	List<String[]> listUsername(String username);
	
	@RolesAllowed({"ADMIN", "USER_READ"})
	List<User> findAll();
	
	@RolesAllowed({"ADMIN", "USER_READ"})
	List<User> find(String filter, Object[] params);
	
	List<User> findRunAs(String filter, Object[] params);
	
	@RolesAllowed({"ADMIN", "USER_READ"})
	long getTotal(String where, Object[] values);
	
	@RolesAllowed({"ADMIN", "USER_READ"})
	List<User> getSplitPage(int start, int limit,
			String where, Object[] params);

	@RolesAllowed({"ADMIN", "USER_READ"})
	User get(String code);
	
	@RolesAllowed({"ADMIN", "USER_DELETE", "ACL_DEL"})
	void delete(User user);
	
	@RolesAllowed({"ADMIN", "USER_ADD"})
	String create(User user);
	
	@RolesAllowed({"ADMIN", "USER_UPDATE", "ACL_PUT"})
	User update(User user);
	
	@RolesAllowed("ACL_PUT")
	User updateSelf(User user);
	
	@RolesAllowed({"ADMIN", "USER_LOCK", "ACL_LOCK"})
	void lock(String[] codes, boolean isLock);
}